var newsService = {
  getNewsList: function (options) {
    var util = require('../utils/util.js');
    var that = this;
    var app = getApp();
    wx.request({
      url: app.getApiPathPrefix() + '/news/getNewsList',
      method: 'POST',
      data: util.signature({
        pageNumber: options.pageIndex,
        pageSize: options.pageSize,
        selectTime: options.selectTime ,
        cityId: options.cityId
      }),
      header: util.buildRequestheader(),
      success: function (res, statusCode) {
        if (res.data.Success) {
          options.success.call(that, res.data.ResultData);
        } else {
          util.processFailureRequest(options.failure, res, statusCode);
        }
      },
      fail: function (a) {
        console.log(a);
        wx.showToast({
          title: '服务器忙，请稍后重试',
          icon: 'loading',
          duration: 2000
        });
      }
    });
  },

  getPolicysList: function (options) {
    var util = require('../utils/util.js');
    var that = this;
    var app = getApp();
    wx.request({
      url: app.getApiPathPrefix() + '/news/getPolicys',
      method: 'POST',
      data: util.signature({
        pageNumber: options.pageIndex,
        pageSize: options.pageSize,
        selectTime: options.selectTime,
        cityId: options.cityId
      }),
      header: util.buildRequestheader(),
      success: function (res, statusCode) {
        if (res.data.Success) {
          options.success.call(that, res.data.ResultData);
        } else {
          util.processFailureRequest(options.failure, res, statusCode);
        }
      },
      fail: function (a) {
        console.log(a);
        wx.showToast({
          title: '服务器忙，请稍后重试',
          icon: 'loading',
          duration: 2000
        });
      }
    });
  },

  getBuildingList: function (options) {
    var util = require('../utils/util.js');
    var that = this;
    var app = getApp();
    wx.request({
      url: app.getApiPathPrefix() + '/news/getParty',
      method: 'POST',
      data: util.signature({
        pageNumber: options.pageIndex,
        pageSize: options.pageSize,
        selectTime: options.selectTime,
        cityId: options.cityId
      }),
      header: util.buildRequestheader(),
      success: function (res, statusCode) {
        if (res.data.Success) {
          options.success.call(that, res.data.ResultData);
        } else {
          util.processFailureRequest(options.failure, res, statusCode);
        }
      },
      fail: function (a) {
        console.log(a);
        wx.showToast({
          title: '服务器忙，请稍后重试',
          icon: 'loading',
          duration: 2000
        });
      }
    });
  },

  getLocalList: function (options) {
    var util = require('../utils/util.js');
    var that = this;
    var app = getApp();
    wx.request({
      url: app.getApiPathPrefix() + '/news/getLocal',
      method: 'POST',
      data: util.signature({
        pageNumber: options.pageIndex,
        pageSize: options.pageSize,
        cityId: options.cityId
      }),
      header: util.buildRequestheader(),
      success: function (res, statusCode) {
        if (res.data.Success) {
          options.success.call(that, res.data.ResultData);
        } else {
          util.processFailureRequest(options.failure, res, statusCode);
        }
      },
      fail: function (a) {
        console.log(a);
        wx.showToast({
          title: '服务器忙，请稍后重试',
          icon: 'loading',
          duration: 2000
        });
      }
    });
  },

  getNewsDetail: function (opt) {
    var util = require('../utils/util.js');
    var that = this;
    var app = getApp();
    wx.request({
      url: app.getApiPathPrefix() + '/news/getNewsDetail',
      method: 'POST',
      data: util.signature({
        id: opt.id
      }),
      header: util.buildRequestheader(),
      success: function (res) {
        if (res.data.Success) {
          opt.success.call(that, res.data.ResultData);
        } else {
          util.processFailureRequest(opt.failure, res);
        }
      },
      fail: function () {
        wx.showToast({
          title: '服务器忙，请稍后重试',
          icon: 'loading',
          duration: 2000
        });
      }
    });
  }
};


module.exports = {
  getNewsList: newsService.getNewsList,
  getNewsDetail: newsService.getNewsDetail,
  getLocalList: newsService.getLocalList,
  getBuildingList: newsService.getBuildingList,
  getPolicysList: newsService.getPolicysList
}